package io.renren.modules.jxgk.service.impl;

import io.renren.common.utils.Query;
import io.renren.modules.jxgk.dao.StudentAttendenceDetailsDao;
import io.renren.modules.jxgk.entity.StudentAttendenceDetailsEntity;
import io.renren.modules.jxgk.service.ClassInfoService;
import io.renren.modules.jxgk.service.StudentAttendenceDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class StudentAttendenceDetailsServiceImpl implements StudentAttendenceDetailsService{
    @Autowired
    StudentAttendenceDetailsDao studentAttendenceDetailsDao;
    @Autowired
    ClassInfoService classInfoService;
    public List<StudentAttendenceDetailsEntity> queryList(Map<String, Object> map){
        List<StudentAttendenceDetailsEntity> list= studentAttendenceDetailsDao.queryList(map);
        for(StudentAttendenceDetailsEntity s:list) {
            if (s.getCourseWhichIndex() != null) {
                int i=Integer.parseInt(s.getCourseWhichIndex())+1;
                String cwi="第"+s.getCourseWhichIndex()+"-"+i+"节";
                s.setCourseWhichIndex(cwi);
            }
        }
        return list;
    }
    public int queryTotal(Map<String, Object> map){
        return  studentAttendenceDetailsDao.queryTotal(map);
    }
    public void deleteBatch(String[] termIds){
        studentAttendenceDetailsDao.deleteBatch(termIds);
    }
    public void save(StudentAttendenceDetailsEntity ste){
        studentAttendenceDetailsDao.save(ste);
    }
    public StudentAttendenceDetailsEntity queryObject(String index){
        return studentAttendenceDetailsDao.queryObject(index);
    }
    public void update(StudentAttendenceDetailsEntity ste){
        studentAttendenceDetailsDao.update(ste);
    }

    @Override
    public List<StudentAttendenceDetailsEntity> getMyStudentAttendenceDetails(Map<String, Object> map) {
        String className=getMyClass(map);
        map.put("className",className);
        List<StudentAttendenceDetailsEntity> list= studentAttendenceDetailsDao.getMyStudentAttendenceDetails(map);

        for(StudentAttendenceDetailsEntity s:list)
        {int i=Integer.parseInt(s.getCourseWhichIndex())+1;
            String cwi="第"+s.getCourseWhichIndex()+"-"+i+"节";
            s.setCourseWhichIndex(cwi);
        }
        return list;
    }

    @Override
    public int getMyStudentAttendenceDetailsTotal(Map<String, Object> map) {
        return  studentAttendenceDetailsDao.getMyStudentAttendenceDetailsTotal(map);
    }
    private String getMyClass(Map<String, Object> map) {
        List<String> list=classInfoService.getMyClass(map);
        StringBuffer strResult=new StringBuffer();
        for(String str:list)
        {
            strResult.append("\'");
            strResult.append(str);
            strResult.append("\'");
            strResult.append(",");
        }
        strResult.deleteCharAt(strResult.length() - 1);
        return strResult.toString();
    }
}
